#ifndef PARSE_H
#define PARSE_H

#include <functional>
#include <vector>
#include <algorithm>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include "jncInterface.h"
#include "XmlTree/XmlTree.h"
#include "jncDefs.h"
#include "jncTemplates.h"
#include "jncTypeInfo.h"
#include "jncFntHandlerDb.h"
#include "jncPrimitives.h"


class Token : public std::string { 
 public : // could'n initialize a string with a range
  inline Token(const std::string::iterator& n, const std::string::iterator& p)
    {insert(begin(), n, p);}
  inline Token(const void* stream)
    {
      if(stream)
	*this = static_cast<const char*>(stream);
    }
  inline Token(const std::string& s) : std::string(s) {}
    Token() {}
};

class XmlContent : public RtmInfo {
 public:
  XmlContent(): RtmInfo(computeId("token.tokenp_void"), (JncInterface*)new CToken(), NULL, (void*) new boost::function<gReturnCode (CToken, jncTypev*)>(MEM_FNTNAME(Token))) {}
    ~XmlContent() 
      {
	/* delete this->getReturn(); */
/* 	delete this->getObject(); */
      }
    inline gReturnCode getContent(const Token& tok) 
      { // TODO: Use Builtin's type system
	jncTypev* tmp = new jncTypev(strndup(tok.c_str(), tok.length()));
	this->ret = std::bind1st(std::mem_fun(MEM_FNTNAME(Token)), this)(tmp); 
	this->stat = COMPLETE;
	return this->ret;
      }
};



/* typedef std::map<Idnb, RtmInfo>   Context; */

class JncContext : public XmlTree::XmlTreeWalker, public RuntimeObject {
 public:
  JncContext(const RuntimeObject& ro, const XmlTree::XmlTreeWalker* xit): RuntimeObject(ro), XmlTree::XmlTreeWalker(*xit) {}
    JncContext(): XmlTree::XmlTreeWalker(SHOW_ALL) {}
      /* static RuntimeObject Transform(CplInfo&, Token); */
/*       static RtmInfo lookupContextTable(CplInfo ci); */
/*       static RuntimeObject createRuntimeObject(std::vector<Token>::iterator& beg, std::vector<Token>::iterator& end, std::vector<CplInfo>::iterator& ci); */
 private:
      /* static Context* ptrcontext; */
};

void Parse(std::list<JncContext>& cxt, XmlTree::XmlTreeWalker* node);
HandlerTable::HandlerInfo::CallBackInfo* getFnParameters(const CplInfo&);

#endif
